package com.tianji.learning.service.impl;

import com.tianji.api.client.ai.AIClient;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.ReplyDTO;
import com.tianji.learning.domain.po.InteractionQuestion;
import com.tianji.learning.service.AIService;
import com.tianji.learning.service.IInteractionReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AIServiceImpl implements AIService {
    @Autowired
    private AIClient aiClient;

    @Autowired
    IInteractionReplyService iInteractionReplyService;

    @Autowired
    private IInteractionReplyService interactionReplyService;

    @Override
    public void autoReply(InteractionQuestion interactionQuestion) {

        String question= String.format("""
                请从专业角度回答用户提问：
                1. 提问的标题是：%s
                2. 提问的问题描述是：%s
                """,interactionQuestion.getTitle(), interactionQuestion.getDescription());


        UserContext.setUser(interactionQuestion.getUserId());

        String textChat = aiClient.TextChat(question);

        ReplyDTO replyDTO=ReplyDTO.builder()
                .userId(9999L)
                .questionId(interactionQuestion.getId())
                .content(textChat)
                .isStudent(false)
                .anonymity(false)
                .build();
        iInteractionReplyService.saveReply(replyDTO);
    }
}
